package net.hvacapp.cmvrfforandroid.widget;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.mirror.android.common.util.ScreenUtils;

import net.hvacapp.cmvrfforandroid.R;

/**
 * 自定义Toast
 * Created by weijia on 15/8/8.
 */
public class CubeadToast extends Toast {

    /**
     * Construct an empty Toast object.  You must call {@link #setView} before you
     * can call {@link #show}.
     *
     * @param context The context to use.  Usually your {@link Application}
     *                or {@link Activity} object.
     */
    public CubeadToast(Context context) {
        super(context);
    }

    @NonNull
    public static Toast makeText(@NonNull Context context, CharSequence text, int duration) {
        Toast toast = new Toast(context);

        View view = View.inflate(context, R.layout.toast, null);
        TextView textView = (TextView) view.findViewById(R.id.tv_content);
        textView.setText(text);

        toast.setView(view);
        toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, (int) ScreenUtils.dpToPx(context, 80));
        toast.setDuration(duration);

        return toast;
    }

}
